package com.zyj.utils.d3.entity;

import java.util.Objects;

/**
 * 空间向量
 */
public class Vector {
    private double a, b, c;

    public Vector(double a, double b, double c) {
        this.a = a;
        this.b = b;
        this.c = c;
        unitization();
    }

    /**
     * 转换成单位向量
     */
    private void unitization(){
        if(a != 0){
            b /= a;
            c /= a;
            a = 1;
        }else if(b != 0){
            a /= b;
            c /= b;
            b = 1;
        }else if(c != 0){
            a /= c;
            b /= c;
            c = 1;
        }
        //其他情况， a = b = c = 0
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()){
            return false;
        }
        Vector vector = (Vector) o;
        return Double.compare(vector.a, a) == 0 &&
                Double.compare(vector.b, b) == 0 &&
                Double.compare(vector.c, c) == 0;
    }

    @Override
    public int hashCode() {
        return Objects.hash(a, b, c);
    }
}
